package com.crm.jdy.service.usermanager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.crm.jdy.common.dto.RoleInfoDto;
import com.crm.jdy.common.pojo.RoleInfo;
import com.crm.jdy.common.mapper.RoleInfoMapper;
import com.crm.jdy.common.pojo.UserInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**   
 * @Description:(角色管理服务实现)
 *
 * @version: V1.0
 * @author: kong
 * 
 */
@Service(version = "${service.version}")
@Component
public class RoleInfoServiceImpl  extends ServiceImpl<RoleInfoMapper,RoleInfo> implements RoleInfoService  {

    @Autowired
    RoleInfoMapper roleInfoDao;

    @Override
    public boolean removeRoleInfo(String aplanId) {
        return roleInfoDao.deleteById(aplanId) > 0;
    }

    @Override
    public boolean addRoleInfo(RoleInfo roleInfo) {
        LambdaQueryWrapper<RoleInfo> lambda = new QueryWrapper<RoleInfo>().lambda().last("limit 1")
                .eq(RoleInfo::getRoleName, roleInfo.getRoleName());
        RoleInfo  clientInfo = roleInfo.selectOne(lambda);
        System.out.println("----------------");
        System.out.println(clientInfo);
        if( clientInfo !=null && !ObjectUtils.isEmpty(clientInfo)){
            return false;
        }else{
            return roleInfoDao.insert(roleInfo) > 0;
        }


    }

    @Override
    public boolean updateRoleInfo(RoleInfo roleInfo) {
        return roleInfoDao.updateById(roleInfo) > 0;
    }

    @Override
    public PageInfo<RoleInfo> seleteRoleInfo(RoleInfoDto callAplanInfoDto) {
       PageHelper.startPage( callAplanInfoDto.getCurrentPage(),callAplanInfoDto.getPageSize());
        List<RoleInfo> bookList = roleInfoDao.seleteRoleInfo(callAplanInfoDto);
        PageInfo<RoleInfo> pageInfo = new PageInfo<RoleInfo>(bookList);
        return pageInfo;
    }
}